/**
 * 查看视频广告
 */
var loadingVideoUrl=null;
var loadingPictureUrl = null;
function viewAd(){
	var adId = getQueryString("adId");
	var adCode = getQueryString("adCode");
	
	if(adId != null){
		
		$.ajax({
			url : '/web-adv/viewAd',
	        data:{adId:adId},
			type : 'post',
			success : function(data) {
				var resultVo = data.resultVo;
				var picServerPrex = resultVo.picServerPrex;
				var videoServerPrex = resultVo.videoServerPrex;
				var ads = data.bean;
				loadingPictureUrl = picServerPrex+ads.adHomepage;

				var duration =   ads.duration+'s'; //广告时长
				$("#adName").html(ads.adName);	//广告名
				$("#advUrl").html(ads.advUrl); //广告链接
				$(".adCoverImg").attr("src",loadingPictureUrl);//广告封面
				//$(".adKeyword").html(ads.adKey);//关键字
				var adKeys = ads.adKey.split("、");
				for(var i =0;i<adKeys.length;i++){
					if(adKeys[i].length !=0){
						$(".adKeyword").append("<span>"+adKeys[i]+"</span>");
					}
				}
				$(".adDescribe").html(ads.description);//描述

				//广告属性标签
				var classfyIds = ads.adClassify.split("|");
				for(var i =0;i<classfyIds.length;i++){
					if(classfyIds[i].length != 0){
						console.log(classfyIds[i]);
						var li = "<li><img src=\"/web-adv/advWeb/static/images/genres_pic"+classfyIds[i]+".png\" alt=\"\" /></li>";
						$("#adClassify").append(li);
					}
				}
				
				//终端  （mobile，pc，pad，tv）手机、PC、PAD、互联网电视
				switch(ads.terminalType){
					case 'mobile':
						loadingVideoUrl = videoServerPrex+ads.mobileVUrl;
						$("#terminal :nth-child(1)").attr("src","/web-adv/advWeb/static/images/mobileIcon.png");
						$("#terminal :nth-child(2)").html("手机");
						$("#size").html(ads.mobileSize);
						$("#adTime").html(duration);
						break
					case 'pc':
						loadingVideoUrl = videoServerPrex+ads.pcVUrl;
						$("#terminal :nth-child(1)").attr("src","/web-adv/advWeb/static/images/pcIcon.png");
						$("#terminal :nth-child(2)").html("PC");
						$("#size").html(ads.pcSize);
						$("#adTime").html(duration);
						break
					case 'pad':
						loadingVideoUrl = videoServerPrex+ads.padVUrl;
						$("#terminal :nth-child(1)").attr("src","/web-adv/advWeb/static/images/padIcon.png");
						$("#terminal :nth-child(2)").html("PAD");
						$("#size").html(ads.padSize);
						$("#adTime").html(duration);
						break
					case 'tv':
						loadingVideoUrl = videoServerPrex+ads.tvVUrl;
						$("#terminal :nth-child(1)").attr("src","/web-adv/advWeb/static/images/tvIcon.png");
						$("#terminal :nth-child(2)").html("互联网电视");
						$("#size").html(ads.tvSize);
						$("#adTime").html(duration);
						break
					default:
				}
				
				//$("#adTime").html(duration);
			},
	        error: function(){}        
		});
		
	}else{
		$.ajax({
			url : '/web-adv/viewAdByAdCode',
	        data:{adCode:adCode},
			type : 'post',
			success : function(data) {
				var resultVo = data.resultVo;
				var picServerPrex = resultVo.picServerPrex;
				var videoServerPrex = resultVo.videoServerPrex;
				var ads = data.bean;
				loadingPictureUrl = picServerPrex+ads.adHomepage;
				var duration =  ads.duration+'s'; //广告时长
				//console.log(ads.adName);
				$("#adName").html(ads.adName);	//广告名
				$("#advUrl").html(ads.advUrl); //广告链接
				$(".adCoverImg").attr("src",picServerPrex+ads.adHomepage);//广告封面
				$(".adKeyword").html(ads.adKey);//关键字
				$(".adDescribe").html(ads.description);//描述

				//广告属性标签
				var classfyIds = ads.adClassify.split("|");
				for(var i =0;i<classfyIds.length;i++){
					if(classfyIds[i].length != 0){
						console.log(classfyIds[i]);
						var li = "<li><img src=\"/web-adv/advWeb/static/images/genres_pic"+classfyIds[i]+".png\" alt=\"\" /></li>";
						$("#adClassify").append(li);
					}
				}
				
				//终端  （mobile，pc，pad，tv）手机、PC、PAD、互联网电视
				switch(ads.terminalType){
					case 'mobile':
						loadingVideoUrl = videoServerPrex+ads.mobileVUrl;
						$("#terminal :nth-child(1)").attr("src","/web-adv/advWeb/static/images/mobileIcon.png");
						$("#terminal :nth-child(2)").html("手机");
						$("#size").html(ads.mobileSize);
						$("#adTime").html(duration);
						break
					case 'pc':
						loadingVideoUrl = videoServerPrex+ads.pcVUrl;
						$("#terminal :nth-child(1)").attr("src","/web-adv/advWeb/static/images/pcIcon.png");
						$("#terminal :nth-child(2)").html("PC");
						$("#size").html(ads.pcSize);
						$("#adTime").html(duration);
						break
					case 'pad':
						loadingVideoUrl = videoServerPrex+ads.padVUrl;
						$("#terminal :nth-child(1)").attr("src","/web-adv/advWeb/static/images/padIcon.png");
						$("#terminal :nth-child(2)").html("PAD");
						$("#size").html(ads.padSize);
						$("#adTime").html(duration);
						break
					case 'tv':
						loadingVideoUrl = videoServerPrex+ads.tvVUrl;
						$("#terminal :nth-child(1)").attr("src","/web-adv/advWeb/static/images/tvIcon.png");
						$("#terminal :nth-child(2)").html("互联网电视");
						$("#size").html(ads.tvSize);
						$("#adTime").html(duration);
						break
					default:
				}
				
				//$("#adTime").html(duration);
			},
	        error: function(){}        
		});
	}
	
}